#pragma once
#include "Runtime/BattleFirePrefix.h"
namespace Alice{
    class ThreadSafeCounter
    {
    public:
        typedef int32 IntegerType;
        ThreadSafeCounter()
        {
            Counter = 0;
        }
        ThreadSafeCounter(const ThreadSafeCounter& Other)
        {
            Counter = Other.GetValue();
        }
        ThreadSafeCounter(int32 Value)
        {
            Counter = Value;
        }
        int32 Increment()
        {
            return ++Counter;
        }
        int32 Add(int32 Amount)
        {
            return Counter.fetch_add(Amount);
        }
        int32 Decrement()
        {
            return --Counter;
        }
        int32 Subtract(int32 Amount)
        {
            return Counter.fetch_sub(Amount);
        }
        int32 Set(int32 Value)
        {
            return Counter.exchange(Value);
        }
        int32 Reset()
        {
            return Counter.exchange(0);
        } 
        int32 GetValue() const
        {
            return Counter.load();
        }
    private:
        void operator=(const ThreadSafeCounter& Other) {}
        std::atomic<int32> Counter;
    };
}
